package cn.fl.project.service.impl;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.dto.PrjStlMDTO;
import cn.fl.project.service.IPrjPrdPaySchMApiService;
import cn.fl.project.service.IPrjStlMService;
import cn.fl.project.transform.PrjStlMVOTransform;
import cn.fl.project.vo.PrjStlMVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 项目产品支付表结清信息表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class PrjStlMServiceImpl implements IPrjStlMService {

    /**
     * 日志
     */
    private static final Logger logger = LoggerFactory.getLogger(IPrjStlMService.class);

    /**
     * TODO 自定义 API 暴露服务
     */
    @Autowired
    private IPrjPrdPaySchMApiService prjPrdPaySchMApiService;

    @Override
    public PrjStlMVO selectById(Long id) throws BaseException {
        if (StringUtils.isEmpty(id)) {
            BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
            return null;
        }
        //TODO 业务逻辑
        PrjStlMDTO dto = null;//this.自定义ApiService.selectById(id);
        return PrjStlMVOTransform.toVO(dto);
    }

    @Override
    public Long add(PrjStlMVO entity) throws BaseException {
        if (null == entity) {
            BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
            return null;
        }
        //return this.prjStlMApiService.add(PrjStlMVOTransform.toDTO(entity));
        //TODO 业务逻辑
        return null;
    }

    @Override
    public boolean removeById(Long id) throws BaseException {
        if (StringUtils.isEmpty(id)) {
            BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
            return false;
        }
        //return this.prjStlMApiService.removeById(id);
        //TODO 业务逻辑
        return false;
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids) throws BaseException {
        if (CollectionUtils.isEmpty(ids)) {
            BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
            return false;
        }
        ;
        return false;
    }

    @Override
    public boolean modify(PrjStlMVO entity) throws BaseException {
        if (null == entity) {
            BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
            return false;
        }
        //return this.prjStlMApiService.modify(PrjStlMVOTransform.toDTO(entity));
        //TODO 业务逻辑
        return false;
    }

    @Override
    public Pager searchListPage(Pager page) throws BaseException {
        if (null == page) page = new Pager();
        //return this.prjStlMApiService.searchListPage(page);
        //TODO 业务逻辑
        return null;
    }

    @Override
    public PrjStlMVO selectByPaySchMId(Long paySchId, String paySchTypCd) throws BaseException {
        PrjStlMVO prjStlMVO = PrjStlMVOTransform.toVO(prjPrdPaySchMApiService.selectByPaySchMId(paySchId, paySchTypCd));
        prjStlMVO = this.coverFenToYun(prjStlMVO);
        return prjStlMVO;
    }

    private PrjStlMVO coverFenToYun(PrjStlMVO prjStlMVO) {
        if (null != prjStlMVO) {
            if (null != prjStlMVO.getRmS01ArTotAmt()) {
                prjStlMVO.setRmS01ArTotAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getRmS01ArTotAmt().longValue()));
            }
            if (null != prjStlMVO.getRmS03TotAmt()) {
                prjStlMVO.setRmS03TotAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getRmS03TotAmt().longValue()));
            }
            if (null != prjStlMVO.getRmS02TotAmt()) {
                prjStlMVO.setRmS02TotAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getRmS02TotAmt().longValue()));
            }
            if (null != prjStlMVO.getRmS03ArTotAmt()) {
                prjStlMVO.setRmS03ArTotAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getRmS03ArTotAmt().longValue()));
            }
            if (null != prjStlMVO.getRmS02ArTotAmt()) {
                prjStlMVO.setRmS02ArTotAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getRmS02ArTotAmt().longValue()));
            }
            if (null != prjStlMVO.getStlOverdueAmt()) {
                prjStlMVO.setStlOverdueAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getStlOverdueAmt().longValue()));
            }
            if (null != prjStlMVO.getStlPenaltyAmt()) {
                prjStlMVO.setStlPenaltyAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getStlPenaltyAmt().longValue()));
            }
            if (null != prjStlMVO.getStlOverduePaidAmt()) {
                prjStlMVO.setStlOverduePaidAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getStlOverduePaidAmt().longValue()));
            }
            if (null != prjStlMVO.getStlPenaltyPaidAmt()) {
                prjStlMVO.setStlPenaltyPaidAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getStlPenaltyPaidAmt().longValue()));
            }
            if (null != prjStlMVO.getRmS03PaidTotAmt()) {
                prjStlMVO.setRmS03PaidTotAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getRmS03PaidTotAmt().longValue()));
            }
            if (null != prjStlMVO.getRmS02PaidTotAmt()) {
                prjStlMVO.setRmS02PaidTotAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getRmS02PaidTotAmt().longValue()));
            }
            if (null != prjStlMVO.getStlAmt()) {
                prjStlMVO.setStlAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getStlAmt().longValue()));
            }
            if (null != prjStlMVO.getStlOverdueS03Amt()) {
                prjStlMVO.setStlOverdueS03Amt(DecimalUtils.convertFenToYuan(prjStlMVO.getStlOverdueS03Amt().longValue()));
            }
            if (null != prjStlMVO.getStlOverdueS02Amt()) {
                prjStlMVO.setStlOverdueS02Amt(DecimalUtils.convertFenToYuan(prjStlMVO.getStlOverdueS02Amt().longValue()));
            }
            if (null != prjStlMVO.getRmS01TotAmt()) {
                prjStlMVO.setRmS01TotAmt(DecimalUtils.convertFenToYuan(prjStlMVO.getRmS01TotAmt().longValue()));
            }
            if (null != prjStlMVO.getA6RmS03Amt()) {
                prjStlMVO.setA6RmS03Amt(DecimalUtils.convertFenToYuan(prjStlMVO.getA6RmS03Amt().longValue()));
            }
            if (null != prjStlMVO.getNoPaidS01Amt()) {
                prjStlMVO.setNoPaidS01Amt(DecimalUtils.convertFenToYuan(prjStlMVO.getNoPaidS01Amt().longValue()));
            }
        }
        return prjStlMVO;
    }
}
